﻿using System;
using System.Windows.Navigation;

namespace Outcoder.NavigationModel
{
	public class NavigatingCancelArgs : EventArgs
	{
		public Uri Uri { get; private set; }

		public NavigationMode NavigationMode { get; private set; }
		public bool Cancellable { get; private set; }
		public bool IsNavigationInitiator { get; private set; }

		public object Parameter { get; private set; }

		public bool Cancel
		{
			get
			{
				return BuiltInArgs != null ? BuiltInArgs.Cancel : cancel;
			}
			set
			{
				if (builtInArgs != null)
				{
					builtInArgs.Cancel = value;
				}
				else
				{
					cancel = value;
				}
			}
		}

		public NavigatingCancelEventArgs BuiltInArgs
		{
			get
			{
				return builtInArgs;
			}
		}

		bool cancel;
		readonly NavigatingCancelEventArgs builtInArgs;

		public NavigatingCancelArgs(
			Uri uri, NavigationMode navigationMode, bool cancellable, bool isNavigationInitiator)
		{
			Uri = uri;
			NavigationMode = navigationMode;
			Cancellable = cancellable;
			IsNavigationInitiator = isNavigationInitiator;
		}

		public NavigatingCancelArgs(NavigatingCancelEventArgs args)
		{
			ArgumentValidator.AssertNotNull(args, "args");

			builtInArgs = args;

			Uri = args.Uri;
			NavigationMode = args.NavigationMode;
		}
	}

	public class NavigationArgs
	{
		public object Content { get; set; }
		public Uri Uri { get; set; }
		public NavigationMode NavigationMode { get; set; }
		public bool IsNavigationInitiator { get; set; }

		public NavigationArgs(
			object content, Uri uri,
			NavigationMode navigationMode = NavigationMode.New, bool isNavigationInitiator = true)
		{
			Content = content;
			Uri = uri;
			NavigationMode = navigationMode;
			IsNavigationInitiator = isNavigationInitiator;
		}

		public NavigationEventArgs BuiltInArgs { get; private set; }

        public NavigationArgs(NavigationEventArgs args)
		{
			ArgumentValidator.AssertNotNull(args, "args");

			Uri = args.Uri;
			Content = args.Content;
			BuiltInArgs = args;
		}
	}
}
